<template>
  <li @mouseenter="enterHandle" @mouseleave="leaveHandle">
    <label >
      <input type="checkbox" v-bind:checked="todo.isDone" @change="update"/>
      <span :class="todo.isDone ? 'active': ''">{{todo.todoName}}</span>
    </label>
    <button class="btn btn-danger" :style="styleObj" @click="deleteFn">删除</button>
  </li>
</template>

<script>
export default {
    data(){
      return {
        //样式对象
          styleObj:{
            display:'none'
          }
      }
    },
    props:['todo',"updateTodo","deleteTodo"],
    methods:{
      //输入内容
      enterHandle(){
         this.styleObj.display = 'block'
      },
      //离开输入内容的文本框
      leaveHandle(){
        this.styleObj.display = 'none'
      },
      //设置更新
      update(){
        // 通知app,修改任务
        const id = this.todo.id
        //更新待办事项
        this.updateTodo(id)

      },
      //设置删除
      deleteFn(){
        //根据id进行删除
        this.deleteTodo(this.todo.id)
      }
    }
}
</script>

<style>
/*item*/
li {
  list-style: none;
  height: 36px;
  line-height: 36px;
  padding: 0 5px;
  border-bottom: 1px solid #ddd;
}

li label {
  /* display:flex; */
  /* align-items: center; */
  float: left;
  cursor: pointer;
}

li label span.active {
  color: #ccc;
  text-decoration: line-through;
}

li label li input {
  vertical-align: middle;
  margin-right: 6px;
  position: relative;
  top: -1px;
}

li button {
  float: right;
  display: none;
  margin-top: 3px;
}

li:before {
  content: initial;
}

li:last-child {
  border-bottom: none;
}
</style>
